Skip to content

completion: shutdown: suggest 'now' for time argument#162

Open
nickshiro wants to merge 1 commit intozsh-users:masterfrom
nickshiro:completion-shutdown-now
Open

completion: shutdown: suggest 'now' for time argument#162
nickshiro wants to merge 1 commit intozsh-users:masterfrom
nickshiro:completion-shutdown-now

Conversation

@nickshiro
Copy link

Current shutdown completion uses _guard for the time argument:

'1: :_guard "^-*" "time (now/hh:mm/+mins)"'

_guard only validates the argument but does not provide completion
candidates. As a result, usage such as:

shutdown n<TAB>

does not complete to shutdown now.

This patch introduces a completion state for the time argument and
adds a suggestion for the commonly used value now. The completion
still allows arbitrary values such as +mins and hh:mm.

Copy link

@skewb1k skewb1k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the same behavior achievable with a simpler change like this?

diff --git a/Completion/Unix/Command/_shutdown b/Completion/Unix/Command/_shutdown
index a237b14e0..a31990a4a 100644
--- a/Completion/Unix/Command/_shutdown
+++ b/Completion/Unix/Command/_shutdown
@@ -11,7 +11,7 @@ if [[ -d /etc/systemd ]]; then
     "(--no-wall)-k[don't shutdown, just write wall message]" \
     "(-k)--no-wall[don't send a wall message]" \
     '-c[cancel pending shutdown]' \
-    '1: :_guard "^-*" "time (now/hh\:mm/+mins)"' \
+    '1: :{ _guard "^-*" "time (now/hh:mm/+mins)" && compadd now }' \
     '*:warning message'
   return
 fi
@@ -23,7 +23,7 @@ case $OSTYPE in
       '-r[reboot the system]'
       '-k[kick everybody off]'
       '-n[prevent file system cache from being flushed]'
-      '1: :_guard "^-*" "time (now/hh\:mm/+mins)"'
+      '1: :{ _guard "^-*" "time (now/hh:mm/+mins)" && compadd now }' \
       '*:warning message'
     )
   ;|

This preserves _guard behavior while also adding completion for 'now'.

While I haven't found similar uses of compadd inline in _arguments, that's probably because it's a relatively rare case where an argument takes on both known and arbitrary values.

@nickshiro
Copy link
Author

@skewb1k, that's a nice simplification.

I wasn't sure whether inline compadd inside _arguments was
acceptable style for completion functions, since most of them use
state-based handling.

If maintainers are fine with this approach I'm switch to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants